package com.youhp.spire.xls.demo.Workbook;

import com.spire.xls.*;

public class DecryptWorkbook {
    public static void main(String[] args) {
        String inputFile = "data/DecryptWorkbook.xlsx";
        String outputFile = "output/DecryptWorkbook_out.xlsx";

        //Detect if the Excel workbook is password protected
        boolean value = Workbook.bookIsPasswordProtected(inputFile);

        if (value)
        {
            //Load a file with the password specified
            Workbook workbook = new Workbook();
            workbook.setOpenPassword("eiceblue");
            workbook.loadFromFile(inputFile);

            //Decrypt the workbook
            workbook.unProtect();

            //Save the Excel file
            workbook.saveToFile(outputFile, ExcelVersion.Version2010);
        }
    }
}
